package springapp.web;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import springapp.service.ProductManager;

@Controller

public class InventoryController {

	private ProductManager productManager;

	@RequestMapping("/hello.htm")
	public ModelAndView handleRequest() {

		String now = (new Date()).toString();
		System.out.println("Returning hello view" + now);
		Map<String, Object> myModel = new HashMap<String, Object>();
		myModel.put("now", now);
		if (this.productManager != null
				&& this.productManager.getProducts() != null) {
			myModel.put("products", this.productManager.getProducts());
		} else {
			if (this.productManager == null)
				System.out.println("TEST:product manager instance is null");
			if (this.productManager.getProducts() == null)
				System.out.println("TEST:no product list");
		}
		return new ModelAndView("hello", "model", myModel);

	}

	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
		System.out.println("TEST:InventoryController.setProductManager");
	}

}
